{% include "header.html" %}

<div class="container">
    <div class="box box-primary">
        <div class="box-header">
            <h4 class="box-title"><span class="fa fa-user"></span>用户登录</h4>
        </div>
        <div class="box-body">
            <form method="post" class="form-horizontal">
                <div class="form-group">
                    <label for="username" class="control-label col-lg-2 col-md-3 col-sm-2 col-xs-3">账号</label>
                    <div class="col-lg-10 col-md-9 col-sm-10">
                        <input id="username" name="username" class="form-control" placeholder="请输入账号" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="password" class="control-label col-lg-2 col-md-3 col-sm-2 col-xs-3">密码</label>
                    <div class="col-lg-10 col-md-9 col-sm-10">
                        <input id="password" name="password" class="form-control" placeholder="请输入密码" type="password" required>
                    </div>
                </div>
                <div class="form-group">
                     <label class="control-label col-lg-12 col-md-12 col-sm-12 col-xs-12">
                         <input name="remember" type="checkbox" value="true" checked> 记住密码
                     </label>
                </div>
                <div class="form-group">
                    <div class="col-lg-12">
                        <button type="submit" class="btn btn-primary btn-block">登录</button>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-lg-6 col-xs-6">
                        <a href="/register" class="text-success"><i class="fa fa-angle-double-right"></i> 点我注册</a>
                    </div>
                    <div class="col-lg-6 col-xs-6 text-right">
                        <a href="/get_back" class="text-warning">忘记密码?</a>
                    </div>
                </div>
            </form>
            {% include "sign.html" %}
        </div>
    </div>
</div>
<script>
    $('form').submit(function (e) {
        e.preventDefault();
{#        console.log($(this).serialize())#}
        $.post('/login', $(this).serialize(), function (data) {
            if (data.status) {
                alert('SUCCESS: 登录成功！');
                {% if prev_url %}
                    location.href = '{{ prev_url }}';
                {% else %}
                    location.href = '/home';
                {% endif %}
            } else {
                alert('ERROR: 登录失败！');
            }
        });
    });
</script>

</body>
</html>